package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author: xuesm
 * @date: 2025/2/23 10:18
 */
// 订单确认页需要用的数据
public class OrderConfirmVo {
    // 收货地址  ums_member_receive_address 表
    @Setter @Getter
    private List<MemberAddressVo> address;
    // 所有选中的购物项
    @Setter @Getter
    List<OrderItemVo> items;
    // 优惠券信息  MemberEntity中积分信息
    @Setter @Getter
    private Integer integration;

    @Setter @Getter
    private String orderToken;
    @Setter @Getter
    private Map<Long, Boolean> stocks;

    // 订单总额
//    BigDecimal total;

    public Integer getCount(){
        int i = 0;
        if (items != null){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }
    public BigDecimal getTotal(){
        BigDecimal sum = new BigDecimal("0");
        if (items != null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    // 应付价格
//    BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
